<template>
  <div class="navbar">
    <div
      class="hamburger-container"
      @click="changeSideBar"
    >
      <i :class="{ 'is-active': isOpen }" class="hamburger  iconfont icon-shousuo"></i>
    </div>
    <!-- 面包屑 -->
    <n-breadcrumb class="breadcrumb-container" />
    <div class="right-menu">
      <!-- 右侧下拉 -->
      <n-dropdown
        @select="handleSelect"
        class="avatar-container right-menu-item hover-effect"
        :options="options"
        trigger="click"
      >
        <n-button class="" :keyboard="false">点击</n-button>
      </n-dropdown>
    </div>
  </div>
</template>

<script>
import { onMounted, reactive, toRef, toRefs, computed } from "vue";
import { useStore } from "vuex";
import { key } from "store";

export default {
  setup() {
    const store = useStore(key);
    const state = reactive({
      options: [
        {
          label: "滨海湾金沙，新加坡",
          key: "marina bay sands",
          disabled: true,
        },
        {
          label: "布朗酒店，伦敦",
          key: "brown's hotel, london",
        },
        {
          label: "亚特兰蒂斯巴哈马，拿骚",
          key: "atlantis nahamas, nassau",
        },
        {
          label: "比佛利山庄酒店，洛杉矶",
          key: "the beverly hills hotel, los angeles",
        },
      ],
    });
    const isOpen = computed(() => {
      return store.state.sidebar;
    });
    const handleSelect = (e) => {
      console.log(isOpen);
    };
    const changeSideBar = () => {
      store.commit("TOGGLE_SIDEBAR");
    };
    return {
      ...toRefs(state),
      handleSelect,
      changeSideBar,
      isOpen,
    };
  },
};
</script>

<style lang="scss" scoped>
.navbar {
  height: 50px;
  overflow: hidden;
  position: relative;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);

  .hamburger-container {
    line-height: 50px;
    height: 100%;
    width: 46px;
    float: left;
    cursor: pointer;
    transition: background 0.3s;
    -webkit-tap-highlight-color: transparent;

    &:hover {
      background: rgba(0, 0, 0, 0.025);
    }

    .hamburger {
      display: inline-block;
      vertical-align: middle;
      width: 50px;
      height: 50px;
    }

    .hamburger.is-active {
      transform: rotate(180deg);
    }
  }

  .breadcrumb-container {
    float: left;
  }

  .right-menu {
    float: right;
    height: 100%;
    line-height: 50px;

    &:focus {
      outline: none;
    }

    .right-menu-item {
      display: inline-block;
      padding: 0 8px;
      height: 100%;
      font-size: 18px;
      color: #5a5e66;
      vertical-align: text-bottom;

      &.hover-effect {
        cursor: pointer;
        transition: background 0.3s;

        &:hover {
          background: rgba(0, 0, 0, 0.025);
        }
      }
    }

    .avatar-container {
      margin-right: 30px;

      .avatar-wrapper {
        margin-top: 5px;
        position: relative;

        .user-avatar {
          cursor: pointer;
          width: 40px;
          height: 40px;
          border-radius: 10px;
        }
      }
    }
  }
}
</style>
